package ru.inse.web;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

import ru.inse.web.module.InseModule;
import ru.xeden.web.html.module.IXedenModuleRegisterService;


public class XedenModuleRegisterServiceTracker
    extends ServiceTracker<IXedenModuleRegisterService, IXedenModuleRegisterService>
{
    private InseModule module;

    public XedenModuleRegisterServiceTracker(BundleContext context, InseModule module)
    {
        super(context, IXedenModuleRegisterService.class, null);
        this.module = module;
    }

    public IXedenModuleRegisterService addingService(ServiceReference<IXedenModuleRegisterService> reference)
    {
        IXedenModuleRegisterService moduleRegisterService = context.getService(reference);
        moduleRegisterService.register(module);
        return moduleRegisterService;
    }

    public void removedService(ServiceReference<IXedenModuleRegisterService> reference,
        IXedenModuleRegisterService service)
    {
        service.unregister(module);
        super.removedService(reference, service);
    }
}